<?php
/**
 * Created by PhpStorm.
 * User: trisatria
 * Date: 1/7/14
 * Time: 11:00 AM
 */

namespace Admin\Model;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class AdminUser
{
    public $id;
    public $name;
    public $email;
    public $address;
    public $phone;
    public $avatar;
    public $password;
    public $time_reg;
    public $status;
    public $user_type;
    public $confirm;
    public $yahooid;
    public $skypeid;
    public $birthday;
    public $telephone ;
    public $zalo;
    public $viber;
    public $kakaotalk;
    protected $inputFilter;

    public function exchangeArray($data)
    {
        $this->id     = (isset($data['id'])) ? $data['id'] : null;
        $this->name = (isset($data['name'])) ? $data['name'] : null;
        $this->email  = (isset($data['email'])) ? $data['email'] : null;

        $this->address     = (isset($data['address'])) ? $data['address'] : null;
        $this->phone = (isset($data['phone'])) ? $data['phone'] : null;
        $this->avatar  = (isset($data['avatar'])) ? $data['avatar'] : '/img/upload/user_temp/person-avatar.png';

        $this->password     = (isset($data['password'])) ? $data['password'] : null;

        $this->time_reg = (isset($data['time_reg'])) ? $data['time_reg'] : time();

        $this->status = (isset($data['status'])) ? $data['status'] : null;
        $this->user_type  = (isset($data['user_type'])) ? $data['user_type'] : null;
        $this->confirm = (isset($data['confirm'])) ? $data['confirm'] : 0;
        $this->yahooid = (isset($data['yahooid'])) ? $data['yahooid'] : null;
        $this->skypeid = (isset($data['skypeid'])) ? $data['skypeid'] : null;
        $this->birthday = (isset($data['birthday'])) ? $data['birthday'] : null;
        $this->telephone = (isset($data['telephone'])) ? $data['telephone'] : null;
        $this->zalo = (isset($data['zalo'])) ? $data['zalo'] : 0;
        $this->viber = (isset($data['viber'])) ? $data['viber'] : 0;
        $this->kakaotalk = (isset($data['kakaotalk'])) ? $data['kakaotalk'] : 0;
    }
        
    //form use
    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $inputFilter = new InputFilter();
            $factory     = new InputFactory();

            $inputFilter->add($factory->createInput(array(
                'name'     => 'id',
                'required' => false,
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'name',
                'required' => false,
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'email',
                'required' => false,
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'address',
                'required' => false,


            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'phone',
                'required' => false,

            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'avatar',
                'required' => false,

            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'password',
                'required' => false,

            )));


            $inputFilter->add($factory->createInput(array(
                'name'     => 'status',
                'required' => true,

            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'user_type',
                'required' => true,

                /*
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min'      => 1,
                            'max'      => 100,
                        ),
                    ),
                ),*/
            )));

            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;
    }
    
    function validateUserFields($postData){
        $result['pass'] = false;
        if (empty ($postData['password'])) $result['message'] = 'Không được bỏ trống mật khẩu';
        if ($postData['password'] != $postData['r_password']) $result['message'] = 'Nhập lại mật khẩu không chính xác';
        if (!isset ($result['message']) || empty ($result['message'])) $result['pass'] = true;
        return $result;
    }
    
}